package xyz.caijiwang.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xyz.caijiwang.entity.Article;
import xyz.caijiwang.entity.Img;
import xyz.caijiwang.mapper.ArticleMapper;
import xyz.caijiwang.mapper.ImgMapper;
import xyz.caijiwang.service.InsertImgService;

@Service
@Transactional(rollbackFor = Exception.class)
public class InsertImgServiceImpl implements InsertImgService {

    @Autowired
    ImgMapper imgMapper;

    @Autowired
    ArticleMapper articleMapper;

    @Override
    public void insertImgToArticle(Img img, Integer articleid) {
        imgMapper.insert(img);
        Integer imgid = img.getImgid();
        Article article = new Article();
        article.setArticleid(articleid);
        article.setImgpathid(imgid);
        articleMapper.updateByPrimaryKeySelective(article);
    }
}
